package fanshe6;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class LoggableAnnotaionTest {
    public static void main(String[] args) throws InvocationTargetException, IllegalAccessException {
        LoggableService service = new LoggableService();
        //在代码运行阶段，通过反射类对象获取 LoggableService所有方法
        Method[] methods = LoggableService.class.getDeclaredMethods();
        for (Method method : methods) {
            if (method.isAnnotationPresent(Loggable.class)) {
                Loggable loggable = method.getAnnotation(Loggable.class);
                System.out.println("要标记的方法是：" + method.getName() + ",日志的级别是" + loggable.leval());

                method.invoke(service);
                //注意：实际项目，下边就可以添加实际的日志记录代码
                System.out.println("实际项目中，根据开发者的注解，生成日志信息");
                System.out.println("日志正在生成中……");

            }else{
                method.invoke(service);
            }
        }


    }
}
